<template>
	<view class="content">
		<view class="pwd">
			<view>
				<text>请输入新密码</text>
				<u-input v-model="pwd1" :password="true"></u-input>
			</view>
			<view>
				<text>请确认新密码</text>
				<u-input v-model="pwd2" :password="true"></u-input>
			</view>
			<view class="btn">
				<u-button @click="updatePwd" type="error" shape="circle">确认</u-button>
			</view>
		</view>
	</view>
</template>

<script>
import { mapActions,mapState } from 'vuex';
	export default {
		data() {
			return {
				pwd1 : '',
				pwd2 : ''
			}
		},
		computed:{
			...mapState('login',['users','log'])
		},
		methods: {
			...mapActions('login',['actionEnrollList','actionLogin','actionUpdate']),
			updatePwd(){
				console.log(this.log);
				if(this.pwd1 !='' && this.pwd2!=''){
					if(this.pwd1 == this.pwd2){
						uni.showToast({
							icon:'none',
							title:'修改成功,请重新登录!'
						})
						let k ={
							account : this.log.account,
							phone : this.log.phone,
							pwd : this.pwd1,
							addr : this.log.addr
						}
						this.users.forEach((item)=>{
							if(this.log.account == item.account){
								this.actionUpdate(k);
							}
						})
						console.log(k);
						this.actionLogin({
							account : '',
							phone : '',
							pwd : '',
							addr : ''
						})
						uni.navigateTo({
							url:'/pages/login/login'
						})
					}else{
						uni.showToast({
							icon:'none',
							title:'修改失败，请确认两次密码是否一致!'
						})
					}
				}else{
					uni.showToast({
						icon:'none',
						title:'密码不能为空'
					})
				}
		
			}
		}
	}
</script>

<style>
.content{
	width: 100%;
}
.pwd{
	width: 96%;
	margin: 10px auto;
}
.pwd view{
	padding: 10px;
	font-size: 16px;
}
.pwd view .u-input{
	margin-top: 10px;
	background-color: #f9f9f9;
}
.pwd .btn{
	width: 75%;
	margin: 20px auto;
}
</style>
